package asteroids.model;

import asteroids.IShip;
import asteroids.ModelException;
import asteroids.Ship;

public class Facade implements asteroids.IFacade{

	@Override
	public IShip createShip() {
		return null;
	}

	@Override
	public IShip createShip(double x, double y, double xVelocity,
			double yVelocity, double radius, double angle) throws ModelException {
		try{
			Ship ship = new Ship(x, y, xVelocity, yVelocity, radius, angle);
			return ship;
		}
		catch(IllegalArgumentException excep){
			throw new ModelException(excep.getMessage());
		}
	}

	@Override
	public double getX(IShip ship) {
		return ((Ship) ship).getXCoordinate();
	}

	@Override
	public double getY(IShip ship) {
		return ((Ship) ship).getYCoordinate();
	}

	@Override
	public double getXVelocity(IShip ship) {
		return ((Ship) ship).getXVelocity();
	}

	@Override
	public double getYVelocity(IShip ship) {
		return ((Ship) ship).getYVelocity();
	}

	@Override
	public double getRadius(IShip ship) {
		return ((Ship) ship).getRadius();
	}

	@Override
	public double getDirection(IShip ship) {
		return ((Ship) ship).getAngle();
	}

	@Override
	public void move(IShip ship, double dt) throws ModelException {
		try{((Ship) ship).move(dt);
		}
		
		catch(IllegalArgumentException excep){
			throw new ModelException(excep.getMessage());
		}
		
	}

	@Override
	public void thrust(IShip ship, double amount) {
		((Ship) ship).thrust(amount);
		
	}

	@Override
	public void turn(IShip ship, double angle) {
		((Ship) ship).addAngle(angle);
		
	}

	@Override
	public double getDistanceBetween(IShip ship1, IShip ship2) throws ModelException{
		try{
		return ((Ship) ship1).getDistanceBetween(((Ship) ship2));
		}
		catch(IllegalArgumentException excep){
			throw new  ModelException(excep.getMessage());
		}
	}

	@Override
	public boolean overlap(IShip ship1, IShip ship2) throws ModelException{
		try{
		return ((Ship) ship1).overlap(((Ship) ship2));
		}
		catch(IllegalArgumentException excep){
			throw new ModelException(excep.getMessage());
		}
	}

	@Override
	public double getTimeToCollision(IShip ship1, IShip ship2) {
		try{
		return ((Ship) ship1).getTimeToCollision(((Ship) ship2));
		}
		catch(IllegalArgumentException excep){
			throw new ModelException(excep.getMessage());
		}
	}

	@Override
	public double[] getCollisionPosition(IShip ship1, IShip ship2) throws ModelException{
		try{
		return ((Ship) ship1).getCollisionPosition(((Ship) ship2));
		}
		catch(IllegalArgumentException excep){
			throw new ModelException(excep.getMessage());
		}
	}

}
